package com.boco.fengke.timelinetest;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

/**
 * Created by fengke on 2016/5/23.
 */
public class TimeLineAdapter extends BaseAdapter {

    private Context mContext;
    private List<Map<String,String>> mList;
    private LayoutInflater inflater;
    private int highlitghtPosition;

    public TimeLineAdapter(Context context,List<Map<String,String>> list) {
        super();
        this.mContext = context;
        this.mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = new ViewHolder();
        if(convertView == null) {
            inflater = LayoutInflater.from(parent.getContext());
            convertView = inflater.inflate(R.layout.timeline_listview, null);
            holder.stateTextView = (TextView)convertView.findViewById(R.id.stateTextView);
            holder.timeTextView = (TextView)convertView.findViewById(R.id.timeTextView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder)convertView.getTag();
        }
        String stateStr = mList.get(mList.size()-position-1).get("Status").toString();
        String timeStr = mList.get(mList.size()-position-1).get("Time").toString();
      //  holder.stateTextView.setText(stateStr);
        holder.timeTextView.setText(timeStr);

        if(highlitghtPosition == position){
            holder.stateTextView.setText("Select");
            Log.d("fengke000", "Select");
        }else{
            holder.stateTextView.setText(stateStr);
        }

        return convertView;
    }

    public void setHighlight(int position){
        highlitghtPosition = position;
//        notifyDataSetChanged();
    }

    static class ViewHolder{
        public TextView stateTextView;
        public TextView timeTextView;
    }
}
